package com.office.automate.dto.convertors;

import javax.servlet.http.HttpServletRequest;

import com.office.automate.frontier.utility.DataConversionUtility;
import com.office.automate.model.leave.LeaveRequest;
import com.office.automate.model.leave.LieuLeaveRequest;

public class LeaveDetailsConvertor {
	private DataConversionUtility dcUtility = new DataConversionUtility();
	public LeaveRequest convertEmployeeLeaveRequest(HttpServletRequest request) {
		LeaveRequest leaveRequest = new LeaveRequest();
		leaveRequest.setLeaveType(request.getParameter("leaveType"));
		leaveRequest.setFromDate(dcUtility.convertToDate(request.getParameter("fromyear") + "-" + request.getParameter("frommonth") + "-" + request.getParameter("fromday")));
		leaveRequest.setToDate(dcUtility.convertToDate(request.getParameter("toyear") + "-" + request.getParameter("tomonth") + "-" + request.getParameter("today")));
		leaveRequest.setReason(request.getParameter("reason"));
		leaveRequest.setFinancialYear(dcUtility.convertStringToNumber(request.getParameter("toyear")));
		return leaveRequest;
	}

	public LeaveRequest convertEmployeeGridRequest(HttpServletRequest request) {
		LeaveRequest leaveRequest = new LeaveRequest();
		leaveRequest.setRequestId(dcUtility.convertStringToLong(request.getParameter("Field6")));
		return leaveRequest;
	}

	public LieuLeaveRequest convertEmployeeLieuLeaveRequest(HttpServletRequest request) {
		LieuLeaveRequest lieuLeaveRequest =  new LieuLeaveRequest();
		lieuLeaveRequest.setLieuLeaveDate(dcUtility.convertToDate(request.getParameter("lieuleaveyear") + "-" + request.getParameter("lieuleavemonth") + "-" + request.getParameter("lieuleaveday")));
		lieuLeaveRequest.setReasonForLeave(request.getParameter("reason"));
		return lieuLeaveRequest;
	}
}